import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;

//zalo�il Rydlobeton;
public class Player {
	private float x;
	private float y;
	private float size = 25.0f;
	private float speed = 0.25f;
	private float angle = 0;
	
	private void getSetAngle(Input in) {
		// třída jenom s lokálními výpočty
		float mouseX = (x - Main.ResX/2) + in.getMouseX();
		float mouseY = (y - Main.ResY/2) + in.getMouseY();
		/*
		g.drawLine(x, y,x,mouseY);
		g.drawLine(x, mouseY, mouseX, mouseY);
		g.drawLine(x,y,mouseX,mouseY);
		*/
		double a = -(y - mouseY);
		double b = -(x - mouseX);
		double ang = Math.toDegrees(Math.atan(a/b));
		ang = Math.abs(ang);
		if(a > 0 && b > 0) {
			angle = (float) (ang);
		}
		if(a > 0 && b < 0) {
			angle = (float) (180 - ang);
		}
		if(a < 0 && b < 0) {
			angle = (float) (180 + ang);
		}
		if(a < 0 && b > 0) {
			angle = (float) (360 - ang);
		}
	}
	
	
	public Player(float x, float y) {
		this.x = x;
		this.y = y;
	}
	
	public void drawPlayer(Graphics g,Input in) {
		g.translate(-x+Main.ResX/2, -y+Main.ResY/2); // dává pohled na hráče do prostřed obrazovky
		g.pushTransform();
		g.rotate(x, y, angle);
		g.fillRect(x,y,size,size);
		g.popTransform();
		// zkušenbně :D

		g.drawLine(-50, 0, 50, 0);
		g.drawLine(0, -50, 0, 50);
	}
	
	public void movePlayer(Input in, int delta) {
		getSetAngle(in);
		if(in.isKeyDown(Input.KEY_W)) { y -= speed*delta;}
		if(in.isKeyDown(Input.KEY_S)) { y += speed*delta;}
		if(in.isKeyDown(Input.KEY_A)) { x -= speed*delta;}
		if(in.isKeyDown(Input.KEY_D)) { x += speed*delta;}
	}
	
}
